#Makefile

JAVA=java

FLEX_MXMLC_JAR=$(FLEX_SDK_PATH)/lib/mxmlc.jar
FLEX_COMPC_JAR=$(FLEX_SDK_PATH)/lib/compc.jar
FLEX_ADT_JAR=$(FLEX_SDK_PATH)/lib/adt.jar

JAVA_PLUS_OPTIONS=${JAVA} -Xmx512m

FLEXLIB_OPTION=+flexlib $(FLEX_SDK_PATH)/frameworks

AIR_CONFIG_FILE=$(FLEX_SDK_PATH)/frameworks/air-config.xml
FLEX_CONFIG_FILE=$(FLEX_SDK_PATH)/frameworks/flex-config.xml

FLEX_APP_COMPILER=$(JAVA_PLUS_OPTIONS) -jar $(FLEX_MXMLC_JAR) $(FLEXLIB_OPTION)
FLEX_LIB_COMPILER=$(JAVA_PLUS_OPTIONS) -jar $(FLEX_COMPC_JAR) $(FLEXLIB_OPTION)
FLEX_AIR_PACKAGER=$(JAVA_PLUS_OPTIONS) -jar $(FLEX_ADT_JAR)

FLASH_PLAYER_TARGET_VERSION=10

SRC_ROOT=src
BIN_DIR=${BIN_TEMP}

DEBUG=true





#default target
all: init api_lib api_asdoc api_tests



#init
init:
	rm -rf ${BIN_DIR}



#api lib
API_ROOT=${SRC_ROOT}/api/MicroBlogAPI
API_SRC_ROOT=${API_ROOT}/src
TARGET_API=${BIN_DIR}/sina-microblog-api-as3.swc
api_lib:
	${FLEX_LIB_COMPILER} -target-player=${FLASH_PLAYER_TARGET_VERSION} -incremental=false -debug=${DEBUG} -load-config=${AIR_CONFIG_FILE} -source-path=${API_SRC_ROOT} -include-sources=${API_SRC_ROOT} -headless-server -output=${TARGET_API}


#api asdoc
API_ASDOC_FOLDER_NAME=api-asdoc
TARGET_API_ASDOC=${BIN_DIR}/${API_ASDOC_FOLDER_NAME}
api_asdoc:
	export FLEX_SDK_PATH=${FLEX_SDK_4} && sh makeASDoc.sh ${TARGET_API_ASDOC}
	cd ${BIN_DIR} && zip -r ${API_ASDOC_FOLDER_NAME}.zip ${API_ASDOC_FOLDER_NAME}


#api_tests
API_TESTS_ROOT=${SRC_ROOT}/api/MicroBlogAPI-tests
api_tests:api_lib
	cd ${API_TESTS_ROOT} && ant test



#api demo
API_DEMO_ROOT=${SRC_ROOT}/api-demo/MicroBlogAPI-Demo
API_DEMO_SRC_ROOT=${API_DEMO_ROOT}/src
API_DEMO_NAME=MicroBlogClient
API_DEMO_MAIN_FILE=${API_DEMO_SRC_ROOT}/${API_DEMO_NAME}.mxml
API_DEMO_DESCRIPTION_FILE=${API_DEMO_SRC_ROOT}/${API_DEMO_NAME}-app.xml
TARGET_API_DEMO_DIR=${BIN_DIR}/${API_DEMO_NAME}
TARGET_API_DEMO=${TARGET_API_DEMO_DIR}/${API_DEMO_NAME}.swf

API_DEMO_LIB_PATH=${API_DEMO_ROOT}/libs,${TARGET_API}

api_demo:
	${FLEX_APP_COMPILER} -target-player=${FLASH_PLAYER_TARGET_VERSION} -incremental=false -debug=${DEBUG} -load-config=${AIR_CONFIG_FILE} -source-path=${API_DEMO_SRC_ROOT}  -library-path+=${API_DEMO_LIB_PATH} -headless-server ${API_DEMO_MAIN_FILE} -output=${TARGET_API_DEMO}

#package api demo
ADT=java -jar -Xmx512m ${FLEX_SDK_PATH}/lib/adt.jar
STORETYPE=PKCS12
KEYSTORE=.api-demo-cert.p12
STOREPASS=123456
APP_NAME=${API_DEMO_NAME}
APP_XML=${APP_NAME}-app.xml
SWF=${APP_NAME}.swf
TARGET_API_DEMO_PACKAGE=${BIN_DIR}/${APP_NAME}.air

deploy_app_description_file:
	sed "s/\(<content>\).*\(<\/content>\)/\1${SWF}\2/g"  ${API_DEMO_DESCRIPTION_FILE} > .tmp
	mv -f .tmp ${TARGET_API_DEMO_DIR}/${APP_XML}

api_demo_package: deploy_app_description_file
	${ADT} -package -storetype ${STORETYPE} -keystore ${KEYSTORE} -storepass ${STOREPASS} ${TARGET_API_DEMO_PACKAGE} ${TARGET_API_DEMO_DIR}/${APP_XML} -C ${TARGET_API_DEMO_DIR} ${SWF}
	rm -rf ${TARGET_API_DEMO_DIR}









#air client


	



